package history.hot100;

// 338. 比特位计数:https://leetcode-cn.com/problems/counting-bits/
public class LeetCode_338 {
    public int[] countBits(int num) {
        if (num<0) return new int[0];
        int []result = new int[num+1];
        result[0] = 0;
        for (int i = 1; i <= num; i++) {
            if (i%2==1) result[i] = result[i-1]+1;
            else result[i] = result[i>>1];
        }
        return result;
    }
}
